const app = getApp()
Page({
  data: {
    loading: true,
    bank: {
      save_money: 0,
    },
    num: 0,
    page: 0,
    list: []
  },
  //生命周期函数--监听页面加载
  onShow: function () {
    app.isLogin(()=>{
      this.getBank();
      this.getApi();
    });
  },
  //下拉
  onReachBottom: function () {
    this.setData({
      loading: true,
    });
    this.getApi();
  },
  //读取我的账户
  getBank: function () {
    var param = {
      signkey: app.util().getRandom(12)
    }
    app.api().Get("api/v4/allwin/bank/index",param,(result) => {
      if (result.code == 200){
        this.setData({
          bank: result.data
        });
      }
    })
  },
  //我的粉丝
  getApi: function () {
    if (this.data.loading) {
      var param = {
        page:this.data.page + 1,
        signkey: app.util().getRandom(12)
      }
      app.api().Get('api/v4/allwin/config/levelUser', param,(rel)=>{
        if (rel.code == 200) {
          var list = this.data.list;
          for (let i in rel.data.list) {
            list.push(rel.data.list[i]);
          }
          this.setData({
            list: list,
            page: param.page,
            num: rel.data.num
          });
        }
      })
    }
    this.setData({
      loading: false,
    });
  },
  //分享按钮
  onShareAppMessage: function (res) {
    return {
      title: '我在【' + app.appname + '】已获得收益 ￥'+this.data.bank.save_money+' 元,加入我一起.',
      path: '/pages/index?ucode=' + app.globalData.loginuser.ucode
    }
  }
})